package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/9 15:41
 * https://www.nowcoder.com/practice/d5e776441a6e41ae9f9859413bdc1eca?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C38KthNumber {
    public static int findKth(int k) {
        if (k <= 0) { return 0; }
        int num3 = 0;
        int num5 = 0;
        int num7 = 0;
        int[] arr = new int[k];
        arr[0] = 3;
        arr[1] = 5;
        arr[2] = 7;
        for (int i = 3; i < k; i++) {
            arr[i] = Math.min(Math.min(arr[num3] * 3, arr[num5] * 5), arr[num7] * 7);
            if (arr[i] == arr[num3] * 3) {
                num3++;
            }
            if (arr[i] == arr[num5] * 5) {
                num5++;
            }
            if (arr[i] == arr[num7] * 7) {
                num7++;
            }
        }
        return arr[k - 1];
    }

    public static void main(String[] args) {
        System.out.println(findKth(5));
    }
}
